﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Manage/Base.Master" AutoEventWireup="true" CodeBehind="AreaList.aspx.cs" Inherits="Exhibition.Manage.AreaList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        $(function () {
            $("#tg").treegrid({
                title: '区域管理列表',
                iconCls: 'icon-ok', 
                animate: true, 
                fitColumns: true,
                toolbar: '#tb',
                url: '../Handler/AdminHandler.ashx?OpType=GetArea&pid=0',
                idField: 'Id',
                onDblClickRow: onClickRow,
                treeField: 'AreaName',
                columns: [[
                           { field: 'Id', title: 'ID', width: 10 },
                           { field: 'ParentId', title: 'ParentId', width: 10,hidden:true },
                           { field: 'AreaName', title: '区域名称', width: 150, editor: 'text' },
                            {
                                field: 'id', title: '操作', width: 80, formatter: function (value, row, index) {
                                    var s = '<a href="javascript:" onclick="Save(' + index + ')">保存</a> <a href="javascript:" onclick="CancelEdit()">取消</a> <a href="javascript:" onclick="DeleteRow('+row.Id+')">删除</a>';
                                    return s;
                                }
                            }

                ]]
            });
        });

        function DeleteRow(id) {
            YXQ.Manager.CommonDel("E_Area",id);
        }

        var editIndex = undefined;
        function endEditing() {
            if (editIndex == undefined) { return true }
            if ($('#tg').treegrid('validateRow', editIndex)) {
                $('#tg').treegrid('endEdit', editIndex);
                editIndex = undefined;
                return true;
            } else {
                return false;
            }
        }

        function onClickRow(index) {
           
            if (editIndex != index.Id) {
                if (endEditing()) {
                    $('#tg').treegrid('selectRow', index.Id)
                            .treegrid('beginEdit', index.Id);
                    editIndex = index.Id;
                } else {
                    $('#tg').treegrid('selectRow', editIndex);
                }
            }
        }
         
        function Save(index) {
          
            if (editIndex != undefined) {
                var t = $('#tg');
                t.treegrid('endEdit', index);
                var select=$('#tg').treegrid('getSelected'); 
                var json = {};
                json.AreaName = select.AreaName;
                json.Id = select.Id;
                json.ParentId = select.ParentId;
                var jsonstring = $.toJSON(json);
              
                YXQ.Manager.SaveArea(jsonstring);
                editIndex = undefined;
                
              
            }
        }
        function CancelEdit() {
            endEditing();
        }
        
    </script>

    <table id="tg"></table>
      <div id="tb" style="height: auto">
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="YXQ.Manager.OpenDialog('AreaDetail.aspx','新增区域')">新增</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="CancelEdit()">取消</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="Save()">保存</a>
    </div>
</asp:Content>
